
package org.jogre.MWLReversi.client;

import info.clearthought.layout.TableLayout;

import org.jogre.client.TableConnectionThread;
import org.jogre.client.awt.GameImages;
import org.jogre.client.awt.JogrePanel;
import org.jogre.client.awt.JogreTableFrame;

// Jogre table frame
public class MWLReversiTableFrame extends JogreTableFrame {

	private MWLReversiModel model;
	private MWLReversiBoardComponent board;
	private MWLReversiScoreComponent score = null;
	private MWLReversiController controller;

	// Constructor which passes a client connection thread and a table
	public MWLReversiTableFrame (TableConnectionThread conn) {
		super (conn);

		// Set icon		
	    this.setIconImage (GameImages.getImage (MWLReversiImages.REVERSI_ICON));

		// Create model, view and register view to model
		model = new MWLReversiModel ();		// create model
		board = new MWLReversiBoardComponent (model);	// board
        score = new MWLReversiScoreComponent (model, 100, 25);
		model.addObserver(board);			    // board observes model
		model.addObserver(score);

		// Create controller which updates model and controlls the view
		controller = new MWLReversiController (model, board);
		controller.setConnection (conn);       // connection
		board.setController(controller);

        // Set up MVC classes in super class
		setupMVC (model, board, controller);

		// Create game panel and add components to it.
		double pref = TableLayout.PREFERRED;
		double[][] size = { { 20, pref, 20 },
				{ 20, pref, 5, pref, 20 } };
		JogrePanel gamePanel = new JogrePanel(size);
		gamePanel.add(board, "1,1,c,t");
		gamePanel.add(score, "1,3,c,t");

		// Add the game panel
		setGamePanel (gamePanel);

		// pack frame
		//pack();
	}
}
